<script src="__LAYUI__/layui.js"></script>
<link href="__LAYUI__/css/layui.css" rel="stylesheet"/>

<table id="table" lay-filter="test"></table>


<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del">删除</a>
</script>



<script>
    layui.use(['table','jquery','layer'], function () {
        var table = layui.table,
            $ = layui.$;
        table.render({
            elem: '#table'
            ,
            id: 'Table'
            ,
            height: 300
            ,
            skin: 'line'
            ,
            even: true
            ,
            size: 'lg'
            ,
            cols: [[
                {field: 'Id', title: 'ID', width: 100},
                {field: 'name', title: '名称', width: 200},
                {field: 'circle', title: '操作周期/月', width: 150},
                {field: 'price', title: '参考价格', width: 100},
                {field: 'remark', title: '备注', width: 500},
                {fixed: 'right', width: 160, align: 'center', toolbar: '#barDemo'}
            ]]

            ,response: {
                statusName: 'code' //数据状态的字段名称，默认：code
                ,statusCode: 1 //成功的状态码，默认：0
            }
            ,url:'/index/Magazine/getMineMagazine'
        });

        table.on('tool(test)',function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            var tr = obj.tr;

            if(layEvent === 'del'){
                layer.open({
                    type:0 ,
                    content:'确定删除?',
                    yes:function (index, layero) {
                        $.ajax({
                            type:'post',
                            url:'/index/Magazine/delMagazine',
                            data:{
                                id:data.Id
                            },
                            success:function (result) {
                                if(result.code){
                                    layer.msg(result.msg, {
                                        icon: 1,
                                        time: 3000 //2秒关闭（如果不配置，默认是3秒）
                                    });
                                }
                                table.reload('Table',{
                                });
                            }
                        });

                        layer.close(index);
                    }

                });
            }
        });
    });
</script>